#!/usr/bin/python
# -*- coding:utf-8 -*-
# @author  : micah
# @time    : 2023/11/28 21:44
# @function: the script is used to do something.
# @version : 


import re

# |匹配左右两边的表达式
# 需求：在列表中["apple","banana", "orange", "pear"]中匹配apple和pear
# fruits = ["apple", "banana", "orange", "pear"]
# for i in fruits:
#     res = re.match('apple|pear', i)
#     if res:
#         print('{}是我想要的'.format(res.group()))
#     else:
#         print(f'{i}不是我想要的数据')

# () 将括号中字符作为分组
# 需求：匹配出163、126、QQ等邮箱信息
# res = re.match('[a-zA-Z0-9_]{4,20}@(163|126|qq)(\.com)', 'hello@163.com')
# print(res)
# print(res.group(2))

# res = re.findall('[a-zA-Z0-9_]{4,20}@(163|126|qq)(\.com)', 'hello@163.com')
# print(res)


# \num
# 需求：匹配出hh
# res = re.match('<([a-zA-Z1-6]+)>.*?</\\1><\\1><\\1><\\1>', "<html>hh</html>")
# print(res.group(1))

# 需求：匹配出www.tuling.cn
# str1 = '<html><h1>www.tuling.cn</h1></html>'
# res = re.match('<([a-zA-Z1-6]+)><([a-zA-Z1-6]+)>.*?</\\2></\\1>', str1)
# print(res.group())

# (?P)(?P=name)
str1 = '<html><h1>www.tuling.cn</h1></html>'
res = re.match('<(?P<name1>[a-zA-Z1-6]+)><(?P<name2>[a-zA-z1-6]+)>.*?</(?P=name2)></(?P=name1)>', str1)
print(res.group())

print(r'\n'[0])



